package com.th.supcom.pds.recipefee.client.widget;

import java.util.List;

import net.carefx.framework.container.client.context.AppContext;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.th.supcom.pds.common.utils.ClientUtils;
import com.th.supcom.pds.config.client.model.PhamDispensaryConfigModel;
import com.th.supcom.pds.config.client.service.PhamDispensaryConfigRpc;
import com.th.supcom.pds.config.client.service.PhamDispensaryConfigRpcAsync;

public class DispensaryDayConfig
{
    private static PhamDispensaryConfigRpcAsync m_phamDispensaryConfigRpcAsync = GWT.create (PhamDispensaryConfigRpc.class);
    private static Integer day = null;
    private static ExecuteDate m_exeCuteDate;
    /**
     * 日志记录器.
     */
    /**
     * 公司版权信息.
     */
    public static final String copyright = "Copyright 2014, Carefx Corporation";

    /**
     * 提交路径.
     */
    public static final String SCC_BRANCH = "$URL$";

    /**
     * 提交日期.
     */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /**
     * 最终修改人员.
     */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /**
     * 最终版本号.
     */
    public static final String SCC_REVISION = "$Revision$";

    private DispensaryDayConfig ()
    {

    }

    /**
     * 查出对应科室允许查询的天数
     * 
     * @param deptCode
     * @return add by Zli
     */
    public static void getLimitedDay (ExecuteDate executeDate)
    {
        m_exeCuteDate = executeDate;
        String deptCode = ClientUtils.getOrgModel().getOrgCode();
        PhamDispensaryConfigModel model = new PhamDispensaryConfigModel ();
        model.setPhamDispensaryCode (deptCode);
        m_phamDispensaryConfigRpcAsync.findPhamDispensaryConfigByExample (model, new AsyncCallback <List <PhamDispensaryConfigModel>> ()
        {

            @Override
            public void onSuccess (List <PhamDispensaryConfigModel> result)
            {
                if (result.isEmpty ())
                {
                    ClientUtils.alertMessageBox ("请检查科室配置", null);
                    return;
                }
                day = result.get (0).getPrescDateBefore ();
                m_exeCuteDate.getDateOrDay (day);

            }

            @Override
            public void onFailure (Throwable caught)
            {
                ClientUtils.alertMessageBox (caught.getLocalizedMessage (), null);

            }
        });
    }

    public interface ExecuteDate
    {
        public void getDateOrDay (Integer day);
    }
}
